package com.http;

import com.bone.HttpRequest;

public class HttpRequestV1 extends HttpRequest {
    @Override
    public void parseContent() {

    }

    @Override
    public void parseHeader() {

    }

    @Override
    public void parseRequestUrl() {

    }

    /**
     * 解析请求行
     *
     * @throws Exception 异常
     */
    @Override
    public void parseRequestLine() throws Exception {
        String line = this.readLine();
        this.setProtocol(line);
    }

    /**
     * 读取一行报文 遇到/r/n结束
     *
     * @return 报文结果
     * @throws Exception 异常
     */
    private String readLine() throws Exception {
        StringBuilder sb = new StringBuilder();
        int nowChar, lastChar = -1;
        while ((nowChar = this.getIs().read()) != -1) {
            if (nowChar == 10 && lastChar == 13) {
                break;
            }
            sb.append((char) nowChar);
            lastChar = nowChar;
        }
        return sb.toString().trim();
    }
}
